package gongju;

import java.sql.*;

public class DBUtil {
   private static final String url = "jdbc:mysql:///AttDB?characterEncoding=utf8";
   private static final String user = "root";
   private static final String password = "root";
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("驱动失败");
            throw new RuntimeException(e);
        }
    }
    public static Connection getcoon() throws SQLException {
        Connection conn = DriverManager.getConnection(url, user, password);
        return conn;
    }
    public static void close(Connection conn,ResultSet re,PreparedStatement pre) {
        try {
            if (re!=null);
            {
                re.close();
            }
            if (pre!=null){
                pre.close();
            }
            if (conn!=null){
                conn.close();
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
//    public static ResultSet qure(String sql) throws SQLException {
//        String sql = "select * from Attence";
//        PreparedStatement pre = getcoon().prepareStatement(sql);
//        ResultSet re = pre.executeQuery();
//        return re;
//    };
}
